﻿@using System.Text.RegularExpressions
@model GlobalTrack.Models.ServerDataModel.TrackingViewModel

@{
    ViewBag.Title = "Edit";
}

<div id="divForm"></div>
<h2>Edit</h2>

@using (Html.BeginForm(new { id = Model.Id }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Tracking</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.User)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.User)
            @Html.ValidationMessageFor(model => model.User)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Comment)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Comment)
            @Html.ValidationMessageFor(model => model.Comment)
        </div>
         @Html.DropDownListFor(model => model.StateId, new SelectList(Model.TrackingItemStates, "Value", "Text"))
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

@{
    var errorMessage = string.Empty;
    if (!String.IsNullOrEmpty(ViewBag.errorsOccurred))
    {errorMessage = ViewBag.errorsOccurred;} 
    else if (TempData["errorsOccurred"] != null)
    {
        errorMessage = TempData["errorsOccurred"].ToString(); 
    }

    if (!string.IsNullOrEmpty(errorMessage))
    {
        <text>
            <script type="text/javascript">
                alert("@Html.Encode(Regex.Replace(errorMessage, @"\t|\n|\r", ""))");
            </script>
        </text>
 }
}
